<?php
/**
 * 游戏大区列表
 *
 * @author xiemaomao@iwgame.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: DwzTree.php 1059 2011-11-18 09:26:15Z mmxie $
 */
class IG_View_Helper_DwzTree extends Zend_View_Helper_Abstract
{
    public function dwzTree($rows, $rootId = 0, $attr = null)
    {
        $data = array($rootId => array('children' => array()));
        $html = "<ul $attr>";
        foreach ($rows as $k => $row) {
            if ($row['parent_id'] != $rootId) continue;
            unset($rows[$k]);
            $external = '';
            if ($row['iframe']) {
                $external = 'external="true"';
            }
            $a = empty($row['url']) ? "<a>{$row['title']}</a>" : '<a '
                                                               . 'target="navTab" '
                                                               . 'fresh="false" '
                                                               . "rel=\"{$row['url']}\" "
                                                               . "href=\"{$row['url']}\""
                                                               . "$external >{$row['title']}</a>";
            $html .= "<li>$a"
                   . $this->dwzTree($rows, $row['id'])
                   . "</li>\n";

        }
        $html .= '</ul>';

        return $html == '<ul ></ul>' ? '' : $html;
    }
}